home *** CD-ROM | disk | FTP | other *** search
- /*
- * AppleEvent Builder test program
- * by Jens Peter Alfke
- *
- * Copyright ©1991 Apple Computer, Inc. All rights reserved.
- *
- * APPLE CONFIDENTIAL
- */
-
- #include <stdio.h>
- #include "AppleEvents.h"
- #include "AEBuild.h"
- #include "AEBuildGlobals.h"
- #include "AEPrint.h"
-
-
- char *AEBuild_ErrMsgs[] = {
- "[No Error!]",
- "Illegal character",
- "Unexpectedly fell off end of line",
- "Extra stuff past end of descriptor",
- "“-” not followed by a number",
- "Missing close “'”",
- "Illegal digit in hex string",
- "Hex string has an odd number of digits",
- "Missing “»”",
- "Hex string must be coerced to some data type",
- "Missing “””",
- "Illegal descriptor",
- "Illegal data value inside parentheses",
- "Missing “)” after data value",
- "Missing “]”",
- "Missing “,” or “]”",
- "Missing keyword in record element",
- "Missing “:” after keyword in record element"
- };
-
-
- const char SampleString[] =
- "obj{ want:type('line'),"
- "from: obj{ want: type('line'), from: docu(), form: 'test',"
- "seld: logi{"
- "term: [comp{ relo:=, obj1:“April”,"
- "obj2:"
- "obj{ want:type('word'), from:exmn(), form:indx, seld:1 }},"
- "comp{ relo:=, obj1:“is”,"
- "obj2:"
- "obj{ want:type('word'), from:exmn(), form:indx, seld:2 }}"
- "],"
- "logc:AND"
- "}"
- "},"
- "form: 'indx',"
- "seld: 1"
- "}";
-
-
- void main( void );
-
-
- void
- main( void )
- {
- OSErr err;
- AEDesc desc;
- char str[1024];
- OSType sig = 'Targ';
- Boolean isEvent;
-
- puts(
- "This program lets you fool around with AEBuild() and AEPrint().\n\
- At the '>' prompt, enter a format string. AEBuild will use the\n\
- string as the template for an AEDesc, AEPrint will convert the\n\
- AEDesc back into a string, and the program will spit out the\n\
- resulting string. If AEBuild reports a syntax error, you'll see the\n\
- approximate location of the error and a message. If either routine\n\
- returns any other error, you'll see the error code.\n");
- puts(
- "To build an entire event, prefix the string with a “\\”.\n\
- \n\
- To build and print a fairly complex sample descriptor, enter a blank line.\n");
-
- do{
- printf("> ");
- gets(str);
-
- isEvent = str[0]=='\\';
- if( isEvent )
- err= AEBuildAppleEvent( 'Some','Evnt',
- typeApplSignature,&sig,sizeof(sig),
- kAutoGenerateReturnID,kAnyTransactionID,
- &desc, str+1 );
- else if( !str[0] ) {
- puts("How's this for a descriptor string:");
- printf(" ");
- puts(SampleString);
- err= AEBuild(&desc, SampleString);
-
- } else
- err= AEBuild(&desc, str);
-
- if( err ) {
- long i;
-
- for( i=0; i<AEBuild_ErrPos+2; i++ )
- putchar(' ');
- printf("^\n\t");
- if( err==aeBuild_SyntaxErr )
- printf("Syntax error: %s\n", AEBuild_ErrMsgs[AEBuild_ErrCode]);
- else
- printf("Error %d in AEBuild!\n",err);
- } else {
- printf("\tBuilt %s. Now formatting it …",
- isEvent ?"Apple event" :"descriptor" );
- err= AEPrint(&desc, str,sizeof(str));
- if( err )
- printf(" Error %d in AEPrint\n");
- else
- printf(" ok. Result:\n\t\t%s\n", str);
- }
- }while( true );
- }
-